/**
 * VectorVector.java
 * Autor: Jennifer Pamela Valdez Cabrera
 * Carne: 10189
 * Fecha de entrega: 8 de octubre de 2011
 * Descripcion: Es la implementacion de una cola con prioridad.
 * @author Jennifer Valdez
 */

import java.util.Vector;

public class PriorityVector<E extends Comparable<E>> implements PriorityQueue<E>{

    protected Vector <E> data;
    
    public PriorityVector(){
        data = new Vector<E>();
    }
    
    @Override
    public E getFirst() {
        return data.get(0);
    }

    @Override
    public E remove() {
        return data.remove(0);
    }

    @Override
    public void add(E value) {
        int position = locate(value);
        data.add(position, value);
    }

    @Override
    public boolean isEmpty() {
        return (data.size() == 0);
    }

    @Override
    public int size() {
        return data.size();
    }

    @Override
    public void clear(){}
    
    protected int locate(E target) {
        Comparable<E> midValue;
        int low = 0;
        int high = data.size();
        int mid = (low + high)/2;
        while (low < high) {
            midValue = (Comparable<E>) data.get(mid);
            if (midValue.compareTo(target)<0) {
                low = mid + 1;
            } else {
                high = mid;
            } 
            mid = (low + high)/2;
        }   
        return low;        
    }
    
}
